<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>照片库案例</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .text {
            padding-left: 600px;
            margin-bottom: 50px;
            font-size: 30px;
            font-family: 'YouYuan';
            color: red;
        }
        
        .full-img {
            margin-left: 530px;
        }
        
        .displayed-img {
            width: 300px;
            height: 300px;
        }
        
        .thumb-bar {
            margin-left: 200px;
            display: flex;
            padding: 20px;
            width: 200px;
            height: 200px;
        }
        
        .dark {
            display: block;
            margin-left: 500px;
        }
    </style>

</head>

<body>
    <h1 class="text">照片库示例</h1>
    <div class="overlay">
        <div class="full-img">
            <img class="displayed-img" src="images/pic1.jpg" />
            <!-- <div class="overlay"></div> -->
        </div>
        <button class="dark">变暗</button>
    </div>

    <div class="thumb-bar"></div>

    <script>
        /** @type {HTMLDivElement}*/
        const thumbBar = document.querySelector('.thumb-bar');
        /** @type {HTMLDivElement}*/
        const overlay = document.querySelector('.overlay');
        /** @type {HTMLImageElement}*/
        const displayedImg = document.querySelector('.displayed-img');
        /** @type {HTMLInputElement}*/
        const button = document.querySelector('.dark');
        let darked = false;

        for (let i = 0; i < 5; i++) {
            let imgSrc = 'images/pic' + (i + 1) + '.jpg';
            const img = document.createElement('img');
            img.src = imgSrc;
            thumbBar.appendChild(img);
        };

        thumbBar.onclick = function(e) {
            /** @type {HTMLImageElement}*/
            const eventImg = e.target;
            console.log(e.target);
            displayedImg.src = eventImg.src;
        };

        button.onclick = function(e) {
            if (darked) {
                button.textContent = '变暗';
                darked = false;
                overlay.style.backgroundColor = 'rgba(0, 0, 0,1)';
            } else {
                button.textContent = '变亮';
                darked = true;
                overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
            }
        };
    </script>


</body>

</html>